<template>
	<view class="">

		<u-sticky>
			<!-- 顶部导航 -->
			<lr-navigation-bar class="navi-bar" title="订单管理" backgroundImageUrl="../../static/car/navigationBar_carBg.png"
				placeholder="请输入车牌号/车架号/订单号/客户名称/车型名称" @searchChange="searchChange" @handleFilter="handleFilter">
			</lr-navigation-bar>

			<!-- 标签控件 -->
			<view class="tab-swiper">
				<u-tabs-swiper activeColor="#1573FF" ref="tabs" :list="list" :current="current" @change="tabChange"
					:is-scroll="false"></u-tabs-swiper>
			</view>

		</u-sticky>		
		
		<screenData @dataChange="screenChange"></screenData>
		
		<mescroll-body ref="mescrollRef222" @init="mescrollInit" @down="downCallback" @up="upCallback">
		
			<uni-list>
				
				<orderListItem v-for="(item, index) in listdata" :key="index" :itemData="item" @itemClick="itemClick">
					
				</orderListItem>
			
			</uni-list>
			
		</mescroll-body>
		
		<!-- 底部导航 -->
		<HomeTabbar :tab="tabNum"></HomeTabbar>
		
	</view>
</template>

<script>
	import lrNavigationBar from "../../components/global/lr-navigation-bar.vue"
	import screenData from "@/components/screen-data.vue"
	import orderListItem from '@/components/order/order-list-item.vue';
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import HomeTabbar from '@/components/tabbar.vue';

	export default {
		mixins: [MescrollMixin],
		components: {
			lrNavigationBar,
			screenData,
			orderListItem,
			HomeTabbar,
		},
		
		data(){
			return{
				list: [],
				current: 0,
				searchVal: '',
				pageNo: 1,
				listdata: [],
				goScreen:false,
				
				sData:{},
				tempStatus:''
			}
		},
		onLoad() {
			
			this.getCountData()
			
			uni.$on('refreshOrder', res=>{
				this.pageNo = 1;
				this.getCountData();
			})
		},
		computed:{
			tabNum(){
				
				if(1==this.$store.state.params.getCarCommon.vehicleListFlag
					&& 1==this.$store.state.params.getCarCommon.vehicleMonitorFlag){
					return 3
				}else if(1!==this.$store.state.params.getCarCommon.vehicleListFlag
					&& 1!==this.$store.state.params.getCarCommon.vehicleMonitorFlag){
					return 1
				}else{
					return 2
				}
			}
		},
		onShow() {
			this.goScreen = false
		},
		onHide() {
			if(!this.goScreen){
				console.log('--------执行清除---------');
				uni.$emit('clearAll', true);
			}
		},
		methods: {
			
			//输入框发生改变监听事件
			searchChange(value) {
				console.log('搜素框内容----' + value);
				this.searchVal = value;
				
				this.pageNo = 1;
				this.getCountData();
			},

			//筛选
			handleFilter() {
				this.goScreen = true
				console.log('点击了筛选');
				uni.navigateTo({
					url: '/pagesB/screen/screen?type=orderScreening'
				})
			},
			
			screenChange(res){
				
				console.log('=页面最终收到筛选变动了=res====', res);
				
				// if(!uni.$u.test.isEmpty(res.statusKey)){
					this.tempStatus = res.statusKey
				// }
				
				this.sData = res;
				
				this.pageNo = 1;
				this.getCountData();
				
			},
			
			//切换标签
			tabChange(index) {
				console.log('标签切换了', index);
				this.current = index;
			
				this.pageNo = 1;
				this.getListData();
			},
			
			getCountData() {
				this.$u.api.orderStatusList({
					...this.sData,
					searchVal: this.searchVal,
				}).then(res => {
					res = res.map(item=>{
						item.num = item.count
						return item
					})
					
					this.list = res;
					
					this.getListData();
				})
			},
			
			getListData() {
				
				if(uni.$u.test.isEmpty(this.tempStatus)){
					if(!uni.$u.test.isEmpty(this.list[this.current])){
						this.sData.statusKey = this.list[this.current].key
					}
				}
				
				// this.sData.statusKey = uni.$u.test.isEmpty(this.sData.statusKey)?this.list[this.current].key:this.sData.statusKey;
				
				this.$u.api.orderlist({
					...this.sData,
					searchVal: this.searchVal,
					pageNo: this.pageNo,
					
				}).then(res => {
					console.log('停止刷新');
					if (this.pageNo == 1) {

            this.listdata = [];
          }
          this.listdata = this.listdata.concat(res);
          this.mescroll.endSuccess(res.length);
        }).catch(() => {
					this.mescroll.endErr();
				})
			},
			
			upCallback(page) {
				console.log("触发了上拉加载" + page);
			
				this.pageNo = page.num;
				this.getListData();
			},
			
			itemClick(item) {
				console.log('item===>', item);
				
				this.goScreen = true
				// uni.navigateTo({
				// 	url: '/pagesA/cardetail/cardetail?id=' + item.carId
				// })
			}

		}
	}
</script>

<style>

</style>
